package xyz.kail.demo.consul.client;

import com.orbitz.consul.Consul;
import com.orbitz.consul.EventClient;
import com.orbitz.consul.async.EventResponseCallback;
import com.orbitz.consul.model.EventResponse;
import com.orbitz.consul.model.event.Event;

import java.io.IOException;
import java.util.List;

/**
 * @author Kail
 * @since 2018/1/16.
 */
public class WatchEventHelloMain {

    static Consul consul = Consul.newClient();

    public static void main(String[] args) throws IOException {

        EventClient eventClient = consul.eventClient();

        eventClient.listEvents(new EventResponseCallback() {
            @Override
            public void onComplete(EventResponse EventResponse) {
                List<Event> events = EventResponse.getEvents();
                for (Event event : events) {
                    System.out.println(event);
                }
                System.out.println();
                System.out.println();
            }

            @Override
            public void onFailure(Throwable throwable) {
                System.out.println(throwable);
            }
        });

        eventClient.fireEvent("asd");
        eventClient.fireEvent("asd","ppppppp");

        System.in.read();

    }

}
